package com.echo.im.infrastructure.mq.event.model.store;


import com.echo.im.common.model.mq.OfflineMsgMqInfo;
import com.echo.im.common.contant.MQConstants;
import com.echo.im.infrastructure.mq.event.AbstractStoreEvent;
import org.apache.commons.lang3.RandomStringUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import java.util.Date;


/**
 * @author echo
 */
@Component
public class OfflineStoreEvent extends AbstractStoreEvent<OfflineMsgMqInfo> {

    @Value(MQConstants.OFFLINE_MESSAGE_TOPIC)
    private String topic;

    @Override
    public EventMessage<OfflineMsgMqInfo> buildEventMessage(OfflineMsgMqInfo offlineMsgMqInfo) {
        return EventMessage.<OfflineMsgMqInfo>builder()
                .id(RandomStringUtils.randomNumeric(11))
                .timestamp(new Date())
                .data(offlineMsgMqInfo)
                .build();
    }

    @Override
    public String topic() {
        return topic;
    }

}
